<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<script src="./js/vue.js"></script>
<body>
    <div class="box">
       <input type="text" v-model="firstName">
       <input type="text" v-model="lastName">
       <input type="text" v-model="fullName1">
       <input type="text" v-model="fullName2">
       <input type="text" v-model="fullName3">
       <button @click="btn">得到fullName4</button>
       <input type="text" v-model="fullName4">
    </div>
    <script>
        /* 姓名   姓  名字 */
        const vm = new Vue({
            el:'.box',
            data:{
                firstName:'a',
                lastName:'b',
                fullName1:'a-b',
                fullName4:''
            },
            methods: {
                btn(){
                    this.fullName4 = this.firstName + '-' + this.lastName;
                }
            },
            computed:{
                // 计算属性的值依赖data当中的值，当data中的值更改 我们的计算属性中的值也进行更改
                // get方式的简写
                fullName2(){
                    return this.firstName + '-' + this.lastName;
                },
                // 计算属性当中有两个方法 getter(获取数据)  setter（劫持数据）
                fullName3:{
                    get(){
                        return this.firstName + '-' + this.lastName;
                    },
                    // 当fullName3已更改就会触发set,value得到更改过后的最新值
                    set(value){
                        console.log(value);
                        // arfuhjk-by  firstName=arfuhjk this.lastName=by
                         const arr = value.split('-');
                         this.firstName = arr[0];
                         this.lastName = arr[1];
                    }
                }
            }
        })
    </script>
</body>
</html>